package com.todo.member.infrastructure.repository.impl;

import com.todo.member.common.enums.MemberVipBoughtStatusEnum;
import com.todo.member.infrastructure.entity.po.MemberVipOrderPO;
import com.todo.member.infrastructure.mapper.MemberVipOrderMapper;
import com.todo.member.infrastructure.repository.MemberVipOrderRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * @author azhebuxing
 * @date 2025/2/11 11:17
 * @description
 */
@Repository
public class MemberVipOrderRepositoryImpl implements MemberVipOrderRepository {


    @Resource
    private MemberVipOrderMapper memberVipOrderMapper;


    @Override
    public Boolean insertMemberVipRelationPO(MemberVipOrderPO memberVipOrderPO) {
        if (memberVipOrderPO == null) {
            return false;
        }
        if (memberVipOrderPO.getVipCode() == null || memberVipOrderPO.getUserId() == null || memberVipOrderPO.getVipId() == null
                || memberVipOrderPO.getBoughtProof() == null || memberVipOrderPO.getPurchaseTime() == null || memberVipOrderPO.getPurchaseAmount() == null) {
            return false;
        }
        return memberVipOrderMapper.insertMemberVipRelationPO(memberVipOrderPO);
    }

    @Override
    public Boolean removeMemberVipRelationPOById(Long id) {
        if (id == null || id <= 0) {
            return false;
        }
        return memberVipOrderMapper.removeMemberVipRelationPOById(id);
    }

    @Override
    public MemberVipOrderPO queryMemberVipRelationPOById(Long id) {
        if (id == null || id <= 0) {
            return null;
        }
        return memberVipOrderMapper.queryMemberVipRelationPOById(id);
    }

    @Override
    public Boolean updateMemberVipRelationStatusById(Long id, MemberVipBoughtStatusEnum oldStatus, MemberVipBoughtStatusEnum newStatus) {
        if (id == null || id <= 0 || oldStatus == null || newStatus == null) {
            return false;
        }
        return memberVipOrderMapper.updateMemberVipRelationStatusById(id, oldStatus.getType(), newStatus.getType());
    }

    @Override
    public List<MemberVipOrderPO> queryMemberVipRelationByUserId(Long userId, MemberVipBoughtStatusEnum status) {
        if (userId == null || userId <= 0) {
            return Collections.emptyList();
        }
        return memberVipOrderMapper.queryMemberVipRelationByUserId(userId, status.getType());
    }
}
